/**
 * 
 */
package br.org.bertol.mestrado;

import java.util.ArrayList;

/**
 * @author Gabriel Bertol Pinheiro
 *
 */
public class Path implements Cloneable
{
	private ArrayList<Integer> route = new ArrayList<Integer>();
	
	private int heigtht = Integer.MAX_VALUE;
	
	public Path()
	{
		
	}

	/**
	 * @param e
	 * @return
	 * @see java.util.List#add(java.lang.Object)
	 */
	public boolean addClass(final Integer e) 
	{
		// evitar adicionar a mesma clase duas vezes no mesmo caminho
		if(route.contains(e))
			return false;
		
		return route.add(e);
	}
	
	/**
	 * @param route the route to set
	 */
	public void setRoute(ArrayList<Integer> route)
	{
		this.route = route;
	}

	public int routeLength() 
	{
		return route.size();
	}	

	/**
	 * @param index
	 * @return
	 * @see java.util.List#remove(int)
	 */
	public boolean removeClass(final Integer index) 
	{
		return route.remove(index);
	}

	/**
	 * @param <T>
	 * @param a
	 * @return
	 * @see java.util.List#toArray(T[])
	 */
	public <T> T[] toArray(T[] a) 
	{
		return route.toArray(a);
	}
	
	public ArrayList<Integer> getRoute()
	{
		return route;
	}
	
	public String toString()
	{
		final StringBuilder buffer = new StringBuilder();

		buffer.append("[ ");
		
		for (Integer element : route) 
		{
			buffer.append(element).append(" ");
		}
		
		buffer.append("]");
		
		return buffer.toString();
	}
	
	
	public void setHeigtht(final int newhHeigtht)
	{
		heigtht = newhHeigtht;
	}
	
	public int gethHeigtht()
	{
		return heigtht;
	}
	
	public void addHeigtht()
	{
		heigtht++;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Object clone() throws CloneNotSupportedException 
	{
		final Path clone = (Path)super.clone();
		
		clone.setRoute((ArrayList<Integer>)this.getRoute().clone());
		
		return clone;
	}
}
